local skill = fk.CreateSkill {
  name = "#ling__tiger_tally_skill",
  attached_equip = "ling__tiger_tally",
}

Fk:loadTranslationTable{
  ["#ling__tiger_tally_skill"] = "虎符",
  ["#ling__tiger_tally-choose"] = "虎符：你可以令一名角色选择使用或获得一张【杀】",
  ["#ling__tiger_tally-slash"] = "虎符：使用一张【杀】，或点“取消”获得一张【杀】",
}

skill:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and player.phase == Player.Draw
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      skill_name = skill.name,
      prompt = "#ling__tiger_tally-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local use = room:askToUseCard(to, {
      skill_name = skill.name,
      pattern = "slash",
      prompt = "#ling__tiger_tally-slash",
      cancelable = true,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      }
    })
    if use then
      room:useCard(use)
    else
      local card = room:getCardsFromPileByRule("slash", 1, "allPiles")
      if #card > 0 then
        room:obtainCard(to, card, true, fk.ReasonJustMove, to, skill.name)
      end
    end
  end,
})

return skill
